# Maintainer: Thore Bödecker <foxxx0@archlinux.org>
# Contributor: brent s. <bts[at]square-r00t[dot]net>
# Contributor: Alexander Phinikarides <alexisph _AT_ gmail _DOT_ com>

pkgbase='python-pyroute2'
_pkgbase="${pkgbase//python-/}"
pkgname=("python-${_pkgbase}")
pkgdesc="A pure Python netlink and Linux network configuration library"
pkgver=0.7.7
pkgrel=2
arch=('any')
url="https://docs.pyroute2.org/"
license=('GPL2' 'Apache')
depends=('python')
makedepends=('python-build' 'python-installer' 'python-wheel' 'python-setuptools')
checkdepends=('python-pytest' 'python-netaddr')
source=("${_pkgbase}-${pkgver}.tar.gz::https://github.com/svinota/${_pkgbase}/archive/${pkgver}.tar.gz")
sha512sums=('c2abf264371e1ce2a098c47b49d321a7ae790450f8c01e51adf8f04e2af07d47db47a0924b0e164530e1f3a1f81459c685fdeb0023ab42396a961514d4e64c51')

prepare() {
  cd "${srcdir}/${_pkgbase}-${pkgver}"

  # Update the version manually. Otherwise it would look for a git tag which is not present in the distribution.
  sed -i "s/version = get_project_version.*$/version = '${pkgver}'/" util/update_version.py
}

build() {
  cd "${srcdir}/${_pkgbase}-${pkgver}"
  python -m build --wheel --no-isolation

  # TODO: building the manpages requires additional packages
  # - python-sphinx (available in repo)
  # - python-aafigure (available in repo)
  # - python-sphinx-code-include (NOT available in repo yet)
  # https://pypi.org/project/sphinx-code-include/

  #export PYTHONPATH="${PWD}"
  #cd docs
  #make man
}

check() {
  cd "${srcdir}/${_pkgbase}-${pkgver}"
  export PYTHONPATH="${PWD}"
  pytest -vv \
    tests/test_minimal/*.py \
    tests/test_unit/*.py
}

package() {
  cd "${srcdir}/${_pkgbase}-${pkgver}"
  python -m installer --destdir="${pkgdir}" dist/*.whl
}

# vim:set ts=2 sw=2 et:
